<?php
/**
 * 城市管理员模块
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2017/12/22
 * Time: 14:56
 */

namespace App\Http\Controllers\MiniProgram;

use App\Http\Logics\MiniProgram\CityLogic;
use App\Http\Traits\CityTrait;
use App\Http\Controllers\BaseController;
class CityController extends BaseController
{
    use CityTrait;

    /**
     * @SWG\Get(
     *     path="/city/recommend",
     *     tags={"City"},
     *     description="获取推荐城市列表",
     *     operationId="recommend",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="limit",
     *         in="query",
     *         description="分页大小",
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function recommend()
    {
        $limit = $this->limit;
        $data = [
            'limit' => $limit,
            'status' => 1,
        ];
        $response = CityLogic::recommend($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Get(
     *     path="/city/list",
     *     tags={"City"},
     *     description="获取城市列表",
     *     operationId="getCityList",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="limit",
     *         in="query",
     *         description="分页大小",
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function getCityList()
    {
        $limit = $this->limit;
        $data = [
            'limit' => $limit,
            'status' => 1
        ];
        $response = CityLogic::getCityList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Get(
     *     path="/city/detail",
     *     tags={"City"},
     *     description="获取城市详情",
     *     operationId="getCityDetail",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         type="string",
     *         required=false
     *     ),
     *     @SWG\Parameter(
     *         name="city_code",
     *         in="query",
     *         description="城市编码",
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="city_id",
     *         in="query",
     *         description="城市ID",
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function getCityDetail(){
        $citycode = $this->citycode;
        $city_id = $this->city_id;
        $loginSession = $this->loginSession;
        $data = [
            'citycode' => $citycode,
            'city_id' => $city_id,
            'loginSession' => $loginSession
        ];
        $response = CityLogic::cityDetail($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);

    }
    public function cityUpdate(){
        $loginSession = $this->loginSession;
        $cityCode = $this->cityCode;
        $slogan = $this->slogan;
        $summary = $this->summary;
        $banner = $this->banner;
        $status = $this->status;
        $data = [
            'loginSession' => $loginSession,
            'cityCode' => $cityCode,
            'slogan' => $slogan,
            'summary' => $summary,
            'banner' => $banner,
            'status' => $status

        ];


        $response = CityLogic::cityUpdate($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Get(
     *     path="/city/search",
     *     tags={"City"},
     *     description="搜索城市",
     *     operationId="searchCity",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="name",
     *         in="query",
     *         description="城市名称",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="limit",
     *         in="query",
     *         description="分页大小",
     *         required=false,
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function searchCity()
    {
        $name = $this->name;
        $limit = $this->limit;
        $data = [
            'name' => $name,
            'limit' => $limit
        ];
        $response = CityLogic::searchCity($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
}